package com.hlhj.carview.http

import com.example.mymvp.log
import com.hlhj.carview.Constant
import com.hlhj.carview.bean.*
import com.lzy.okgo.OkGo
import com.lzy.okgo.cache.CacheMode
import com.lzy.okgo.convert.StringConvert
import com.lzy.okgo.model.HttpParams
import com.lzy.okgo.model.Response
import com.lzy.okgo.request.PostRequest
import com.lzy.okrx2.adapter.ObservableResponse
import io.reactivex.Observable
import io.reactivex.schedulers.Schedulers
import java.io.File
import java.net.URL

/**
 * Created by Never Fear   on 2019\1\4 0004.
Never More....
 */
object Apis {
    //验证码
    fun sendSMS(phone:String): Observable<Response<MyBaseBean>>? {
       return OkGo.post<MyBaseBean>(Urls.SendSms)
                .params("phone",phone)
                .converter(object :MyJsonConvert<MyBaseBean>(){})
                .adapt(ObservableResponse<MyBaseBean>())
                .subscribeOn(Schedulers.io())
    }
    //注册
    fun regis(phone:String,code:String,password:String,confirmPassword:String): Observable<Response<MyBaseBean>>? {
     return   OkGo.post<MyBaseBean>(Urls.Regis)
                .params("phone",phone)
                .params("code",code)
                .params("password",password)
                .params("confirmPassword",confirmPassword)
                .converter(object :MyJsonConvert<MyBaseBean>(){})
                .adapt(ObservableResponse<MyBaseBean>())
                .subscribeOn(Schedulers.io())

    }
    //登录
    fun login(phone: String,password:String): Observable<Response<LoginBean>>? {
       return OkGo.post<LoginBean>(Urls.Login)
                .params("phone",phone)
                .params("password",password)
                .converter(object :MyJsonConvert<LoginBean>(){})
                .adapt(ObservableResponse<LoginBean>())
                .subscribeOn(Schedulers.io())
    }
    //修改密码
    fun changePwd(phone: String,code:String,password:String,confirmPassword:String): Observable<Response<MyBaseBean>>? {
       return OkGo.post<MyBaseBean>(Urls.changPwd)
                .params("phone",phone)
                .params("code",code)
                .params("password",password)
                .params("confirmPassword",confirmPassword)
                .converter(object :MyJsonConvert<MyBaseBean>(){})
                .adapt(ObservableResponse<MyBaseBean>())
                .subscribeOn(Schedulers.io())
    }
    //用户信息
    fun getUserInfo(): Observable<Response<UserInfoBean>>? {
      return  OkGo.get<UserInfoBean>(Urls.UserInfo)
               .cacheKey("userInfo")
               .cacheMode(CacheMode.FIRST_CACHE_THEN_REQUEST)
               .cacheTime(-1)
                .converter(object :MyJsonConvert<UserInfoBean>(){})
                .adapt(ObservableResponse<UserInfoBean>())
                .subscribeOn(Schedulers.newThread())
    }
    //上传文件
    fun upload(file:File): Observable<Response<MyBaseBean>>? {
      return  OkGo.post<MyBaseBean>(Urls.upLoad)
                .params("source",file)
                .converter(object :MyJsonConvert<MyBaseBean>(){})
                .adapt(ObservableResponse<MyBaseBean>())
                .subscribeOn(Schedulers.io())
    }
    //实名认证
    fun identify(id_front:String,id_back:String,travel_front:String,travel_back:String,driving_front:String,driving_back:String): Observable<Response<MyBaseBean>>? {
        return OkGo.post<MyBaseBean>(Urls.identify)
                .params("id_front",id_front)
                .params("id_back",id_back)
                .params("travel_front",travel_front)
                .params("travel_back",travel_back)
                .params("driving_front",driving_front)
                .params("driving_back",driving_back)
                .converter(object :MyJsonConvert<MyBaseBean>(){})
                .adapt(ObservableResponse<MyBaseBean>())
                .subscribeOn(Schedulers.io())
    }
    //头像
    fun changeHead(head_img:String): Observable<Response<MyBaseBean>>? {
       return OkGo.post<MyBaseBean>(Urls.changeHead)
                .params("head_img",head_img)
                .converter(object :MyJsonConvert<MyBaseBean>(){})
                .adapt(ObservableResponse<MyBaseBean>())
                .subscribeOn(Schedulers.io())
    }
    //设备保修
    fun repair(device_id:Int,proposer:String,proposer_phone:String,wechat:String,cause:String,img:String): Observable<Response<MyBaseBean>>? {
      return  OkGo.post<MyBaseBean>(Urls.repair)
                .params("device_id",device_id)
                .params("proposer",proposer)
                .params("proposer_phone",proposer_phone)
                .params("wechat",wechat)
                .params("cause",cause)
                .params("img",img)
                .converter(object :MyJsonConvert<MyBaseBean>(){})
                .adapt(ObservableResponse<MyBaseBean>())
                .subscribeOn(Schedulers.io())
    }
    //添加车辆

    fun addCar(car_number:String,number_type:String,car_type:String,car_appearance:String,img:String): Observable<Response<MyBaseBean>>? {
      return  OkGo.post<MyBaseBean>(Urls.addCar)
                .params("car_number",car_number)
                .params("number_type",number_type)
                .params("car_type",car_type)
                .params("car_appearance",car_appearance)
                .params("img",img)
                .converter(object :MyJsonConvert<MyBaseBean>(){})
                .adapt(ObservableResponse<MyBaseBean>())
                .subscribeOn(Schedulers.io())
    }
    //车辆信息
    fun carInfo(): Observable<Response<CarInfoBean>>? {
       return OkGo.get<CarInfoBean>(Urls.carInfo)
                .converter(object :MyJsonConvert<CarInfoBean>(){})
                .adapt(ObservableResponse<CarInfoBean>())
                .subscribeOn(Schedulers.io())
    }
    //添加设备
    fun addEquipment(name:String,phone:String,wechat:String): Observable<Response<MyBaseBean>>? {
       return OkGo.post<MyBaseBean>(Urls.addEquipment)
                .params("name",name)
                .params("phone",phone)
                .params("wechat",wechat)
               .converter(object :MyJsonConvert<MyBaseBean>(){})
               .adapt(ObservableResponse<MyBaseBean>())
               .subscribeOn(Schedulers.io())
    }
    //关于我们
    fun getAboutUs(): Observable<Response<MyBaseBean>>? {
        return OkGo.get<MyBaseBean>(Urls.aboutUs)
                .converter(object :MyJsonConvert<MyBaseBean>(){})
                .adapt(ObservableResponse<MyBaseBean>())
                .subscribeOn(Schedulers.io())
    }
    //意见反馈
    fun report(content:String): Observable<Response<MyBaseBean>>? {
      return  OkGo.post<MyBaseBean>(Urls.report)
                .params("content",content)
                .converter(object :MyJsonConvert<MyBaseBean>(){})
                .adapt(ObservableResponse<MyBaseBean>())
                .subscribeOn(Schedulers.io())
    }

    //提现规则
    fun getCashRule(): Observable<Response<MyBaseBean>>? {
       return OkGo.get<MyBaseBean>(Urls.getCashRule)
                .converter(object :MyJsonConvert<MyBaseBean>(){})
                .adapt(ObservableResponse<MyBaseBean>())
                .subscribeOn(Schedulers.io())
    }
    //设备列表
    fun getEquipmentList(page:Int): Observable<Response<EquipmentListBean>>? {
       return OkGo.get<EquipmentListBean>(Urls.equipmentList)
               .params("page",page)
                .converter(object :MyJsonConvert<EquipmentListBean>(){})
                .adapt(ObservableResponse<EquipmentListBean>())
                .subscribeOn(Schedulers.io())
    }
    //设备详情
    fun getEquipmentDetail(did:Int): Observable<Response<EquipmentDetailBean>>? {
       return OkGo.get<EquipmentDetailBean>(Urls.equipmentDetail)
                .params("device_id",did)
                .converter(object :MyJsonConvert<EquipmentDetailBean>(){})
                .adapt(ObservableResponse<EquipmentDetailBean>())
                .subscribeOn(Schedulers.io())
    }
    //提现
    fun getCash(account:String,type:Int,money:String): Observable<Response<MyBaseBean>>? {
       return OkGo.post<MyBaseBean>(Urls.getCash)
                .params("account",account)
                .params("type",type)
                .params("money",money)
                .converter(object :MyJsonConvert<MyBaseBean>(){})
                .adapt(ObservableResponse<MyBaseBean>())
                .subscribeOn(Schedulers.io())
    }
    //广告列表
    fun getAdv(page:String?): Observable<Response<AdvListBean>>? {
       return OkGo.get<AdvListBean>(Urls.getAdv)
                .params("page",if (page==null) "" else page)
                .converter(object :MyJsonConvert<AdvListBean>(){})
                .adapt(ObservableResponse<AdvListBean>())
                .subscribeOn(Schedulers.io())
    }
    //获取7次
    fun getLastSeven(): Observable<Response<LastSevenbean>>? {
       return OkGo.get<LastSevenbean>(Urls.getLastSevent)
                .converter(object :MyJsonConvert<LastSevenbean>(){})
                .adapt(ObservableResponse<LastSevenbean>())
                .subscribeOn(Schedulers.io())
    }
    //获取六月
    fun getMonths(): Observable<Response<MothsBean>>? {
       return OkGo.get<MothsBean>(Urls.getMoths)
                .converter(object :MyJsonConvert<MothsBean>(){})
                .adapt(ObservableResponse<MothsBean>())
                .subscribeOn(Schedulers.io())
    }
    //广告详情
    fun getAdvDetail(advertising_id:Int): Observable<Response<AdvDetailBean>>? {
       return OkGo.get<AdvDetailBean>(Urls.advDetail)
                .params("advertising_id",advertising_id)
                .converter(object :MyJsonConvert<AdvDetailBean>(){})
                .adapt(ObservableResponse<AdvDetailBean>())
                .subscribeOn(Schedulers.io())
    }
    //获取收益详情
    fun getGainDetail(page:Int): Observable<Response<GainDetailBean>>? {
       return OkGo.get<GainDetailBean>(Urls.gainDetail)
               .params("page",page)
                .converter(object :MyJsonConvert<GainDetailBean>(){})
                .adapt(ObservableResponse<GainDetailBean>())
                .subscribeOn(Schedulers.io())
    }
    //抽成
    fun choucheng(advertising_id:Int,advertising_name:String): Observable<Response<MyBaseBean>>? {
       return OkGo.post<MyBaseBean>(Urls.choucheng)
                .params("advertising_id",advertising_id)
                .params("advertising_name",advertising_name)
                .converter(object :MyJsonConvert<MyBaseBean>(){})
                .adapt(ObservableResponse<MyBaseBean>())
                .subscribeOn(Schedulers.io())
    }
    //天气
    fun getWeather(city:String): Observable<Response<String>>? {
        log("okgo","来？${city}")
       return OkGo.get<String>(Urls.weather)
                .params("appkey","dda859cbdc2d0c1e25f7d69f1b771760")
                .params("city",city)
                .converter(object :StringConvert(){})
                .adapt(ObservableResponse<String>())
                .subscribeOn(Schedulers.io())
    }
    ///////////------------------------------------------------------------------
    fun getMainPagers(): Observable<Response<MainPagerBean>>? {
       return OkGo.post<MainPagerBean>(Urls.PubUrl)
                .headers("type","3")
                .params("uriPath","homePager")
                .converter(object :MyJsonConvert<MainPagerBean>(){})
                .adapt(ObservableResponse<MainPagerBean>())
                .subscribeOn(Schedulers.io())
    }
    //注册
    fun newRegis(phone:String,pwd:String): Observable<Response<MyBaseBean>>? {
      return  OkGo.post<MyBaseBean>(Urls.PubUrl)
                .headers("type","1")
                .params("phone",phone)
                .params("pwd",pwd)
                .converter(object :MyJsonConvert<MyBaseBean>(){})
                .adapt(ObservableResponse<MyBaseBean>())
                .subscribeOn(Schedulers.io())
    }
    //登录
    fun newLogin(phone:String,pwd:String): Observable<Response<MyBaseBean>>? {
        return  OkGo.post<MyBaseBean>(Urls.PubUrl)
                .headers("type","3")
                .params("phone",phone)
                .params("pwd",pwd)
                .converter(object :MyJsonConvert<MyBaseBean>(){})
                .adapt(ObservableResponse<MyBaseBean>())
                .subscribeOn(Schedulers.io())
    }


}